<template>
    <div>
        <div class="centent">
            <div class="successful_pay">
                <i class="icon njfont nj-xuanzhong"></i>
                <h1>支付成功</h1>
                <p>您的订单会尽快处理</p>
                <p>
                <span style="color: #EA3939;">{{time}}</span>秒后自动跳转</p>
                <div class="aui-btn aui-btn-outlined aui-btn-danger" @click.stop="goToOrderList">查看我的订单</div>
            </div>
        </div>
    </div> 
</template>
<script>
// import api from "../../api";
import getSearch from "../../utils/getUrlSearch";
import {orderTypes} from "../../config/orderTypeCode";
import * as types from "../../config/postMessage-types";
export default {
    props: {

    },
    data() {
        return {
            time: 5,
            timer: null
        }
    },
    computed: {
        //获取订单编号
        orderType() {
            // console.log("支付成功页面", this.$route.params.orderType);
            return getSearch().orderType || this.$route.params.orderType;
        },
    },
    components: {

    },
    methods: {
        goToOrderList() {
            //设置tag
            let exit = {
                type: types.EXIT_WEBVIEW
            };
            //跳转订单列表页面
            let navigate = {
                type: types.NAVIGATE,
                params: {
                    screen: "Order",
                    params: {
                        page: this.orderType === orderTypes.normal ? 2 : 0
                    }
                }
            }
            //取消定时器
            if (this.timer) {
                clearInterval(this.timer);
                this.timer = null;
            }
            //订单类型，线上订单为2（跳转到待配送），线下订单为1（跳转到全部）
            window.postMessage(JSON.stringify([exit, navigate]));
            // if (this.orderType + "" === orderTypes.normal) {
            //     this.$router.replace({path: `order`, query: {orderStatus: 2}});
                
            // } else {
            //     this.$router.replace({path: `order`, query: {orderStatus: 0}});
            // }
            
        },
        goBack() {
            this.goToOrderList();
        },
        setNativeBackFlagForPayIsFalse() {
            this.$store.commit("setNativeBackFlagForPay", false);
        }
    },
    created () {
        // console.log("这是支付成功页面");
        this.setNativeBackFlagForPayIsFalse();
        if (!this.timer) {
            this.timer = setInterval(() => {
                if (this.time === 0) {
                    clearInterval(this.timer);
                    this.timer = null;
                    this.goToOrderList();
                    return;
                }
                this.time = this.time - 1;
            }, 1000);
        }
    },
    beforeDestory() {
        //取消定时器
        if (this.timer) {
            clearInterval(this.timer);
            this.timer = null;
        }
    }

}
</script>

<style scoped>
.successful_pay i {
    display: inline-block;
    font-size: 1.6rem;
    color: #ffffff;
    background: #EA3939;
    border-radius: 100%;
    padding: 0.5rem;
    margin: 0.75rem;
}
.successful_pay p{
    margin-top: 10px;
}
.aui-btn {
    margin-top: 10px;
}
</style>


